'use strict';
const db = uniCloud.database();

module.exports = {
	/**
	 * 此函数名称
	 * @url user/pub/test1 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		// 可写与数据库的交互逻辑等等
		let chatGptKey = await db.collection('wx_config').where({
			'key': 'chatGptKey'
		}).get()
		
		if (chatGptKey.data.length === 0) {
			return '未配置chatGptKey'
		}
		const _chatGptKey = chatGptKey.data[0].val
	
		const cont = await uniCloud.httpclient.request('https://ai.shenqiwang.top/api/stream', {
			timeout:30000,
			headers: {

			},
			data: {
				"messages": [{
					"role": "user",
					"content": data.content
				}],
				"key": _chatGptKey,
				"temperature": 0.6
			},
			method: "POST",
			contentType: 'json',
			dataType: "text"
		})
		
		console.log(cont.data,'121212121')
		res.data = cont.data
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
